package org.example.ssm.service.impl;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.example.ssm.gof.BuilderGoF;
import org.example.ssm.mapper.UserMapper;
import org.example.ssm.po.User;
import org.example.ssm.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 莫磊
 * @date 2025/8/16
 * @description
 */
@Slf4j
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public void saveUser(User user) {
        User user1 = userMapper.selectByName(user.getName());
        if (user1 != null) {
            log.info("用户已存在");
        } else
            userMapper.insert(user);
    }

    @Override
    public User getById(Integer id) {
        return userMapper.selectById(id);
    }

    @Override
    public User getByName(String name) {
        return userMapper.selectByName(name);
    }

    @Override
    @Transactional
    public List<User> getAll() {
        return userMapper.selectAll();
    }
}
